library(gridExtra)
library(readstata13)
library(ggplot2)
library(gridExtra)
library(foreign)
library(MASS)
library(Matrix)
library(lattice)
library(rdd)
library(foreign)
library(ri)
library(scales)

rm(list = ls())
setwd("~/Dropbox/Two habits formed hand-in-hand/Two habits formed in the shadow of the voting booth/")




###################
#Figure 4, Panel B#
###################






theme_base1 <- 
  theme_minimal(base_size=15)  + 
  theme(legend.position=c(0.1, .1),  legend.key.size = unit(1,"line"),
        axis.text=element_text(size=16),axis.title.x=element_text(size=14),axis.title.y=element_text(size=16),
        plot.title = element_text(size=16, hjust= 0.5))

data <- read.dta("Data/samealltogetherInt.dta")

data$grp<-as.factor(data$id3)


main<-ggplot(data, aes(x=id, y =estimate ,color=grp)) +   
  geom_point(size = 2,position=position_dodge(0.35)) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.7,position=position_dodge(width=0.35))+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=1.6,position=position_dodge(width=0.35))+
  scale_color_manual(name="Election",labels=c("Presidential","Same-Type", "Midterm"),values=c("blue","black","red")) + 
  scale_y_continuous(limits = c(-.22, .21))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.75,15.25))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Difference in Interest in the Election:\n Same vs different type of First-eligible-election") 
main
ggsave("Graphs/Alltogether15Int.pdf", width = 22, height = 18, units = "cm")  
